var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function(t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
    instanceof Array &&
    function(t, e) {
        t.__proto__ = e
    } ||
    function(t, e) {
        for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
    })(t, e)
},
function(t, e) {
    function o() {
        this.constructor = t
    }
    i(t, e),
    t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
}),
a = this && this.__decorate ||
function(t, e, o, i) {
    var n, a = arguments.length,
    r = a < 3 ? e: null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
    else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
    return a > 3 && r && Object.defineProperty(e, o, r),
    r
};
Object.defineProperty(o, "__esModule", {
    value: !0
});
var r, s = t("Util"),
l = t("CarConstant"),
c = t("BoxGetView"),
d = t("HallScene"),
h = t("GlobalUserData"),
p = t("Bounce"),
u = t("Global"),
f = t("BaseStorage"),
m = t("BoxGetItem"),
_ = t("WXSDK"),
y = t("NativeManager"),
g = cc._decorator,
v = g.ccclass,
C = g.property; (function(t) {
    t[t.gold = 0] = "gold",
    t[t.diamond = 1] = "diamond"
})(r || (r = {}));
var b = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.pfb_showItem = null,
        e.node_showItem = null,
        e.boxPrefab = null,
        e.valueLabel = null,
        e.nameLabel = null,
        e.icon = null,
        e.gold = null,
        e.diamond = null,
        e.giftPanel = null,
        e.cancelPanel = null,
        e.nameReward = null,
        e.closeNode = null,
        e.btnClose = null,
        e.btnShowAd = null,
        e.videoIcon = null,
        e.TTVideoIcon = null,
        e.videoIcon2 = null,
        e.TTVideoIcon2 = null,
        e.itemScript = null,
        e.allItemsData = [],
        e.bonusData = {
            type: 0,
            value: 0,
            data: null
        },
        e.mistakeBannerTimer = null,
        e.btnCancel = null,
        e.btnGet = null,
        e.btnCancel2 = null,
        e.btnGet2 = null,
        e.isBtnClickOnce = !1,
        e
    }
    return n(e, t),
    e.prototype.start = function() {
        var t = this;
        s.Util.is_tt() && (this.videoIcon.active = !1, this.TTVideoIcon.active = !0, this.videoIcon2.active = !1, this.TTVideoIcon2.active = !0, this.closeNode.active = !1, this.btnClose.active = !0, this.btnShowAd.active = !1, this.btnCancel.active = !1, this.btnCancel2.active = !1, h.default.bAuditMode ? (this.btnClose.active = !1, this.btnGet.x = 130, this.btnGet2.x = 130, this.btnCancel.active = !0, this.btnCancel2.active = !0) : setTimeout(function() {
            t.onBtnClick()
        },
        1e3)),
        s.Util.hideHallBanner()
    },
    e.prototype.onEnable = function() {
        s.Util.hideSingleCustomAd(),
        s.Util.show_VerticalCustomAd(!1),
        s.Util.show_VerticalCustomAd(!0),
        s.Util.is_233() && y.default.instance.showFullVideoAd()
    },
    e.prototype.initView = function(t, e, o) {
        if (!this.itemScript) {
            var i = cc.instantiate(this.pfb_showItem);
            this.node_showItem.addChild(i),
            this.itemScript = i.getComponent(m.default)
        }
        if (this._call = e, this._canel = o, t) {
            var n = cc.sys.localStorage.getItem(u.BaseStorageKey.GiftPackageBonus),
            a = void 0;
            if (n) {
                var l = JSON.parse(n);
                switch (this.tipo = l.type, this.value = l.value, this.tipo) {
                    case r.diamond:
                        this.icon.spriteFrame = this.diamond;
                    break;
                    default: this.icon.spriteFrame = this.gold;
                }
                this.valueLabel.addComponent(p.default).init(1, this.value),
                this.nameLabel.string = l.data.name,
                a = {
                    data: l.data,
                    star: 3
                },
                this.itemScript.updateView(this.getCarItemData(a.data, a.star)),
                this.allItemsData.push(this.getCarItemData(a.data, a.star))
            }
        } else {
            switch (this.tipo = Math.random() > .5 ? r.diamond: r.gold, this.bonusData.type = this.tipo, this.tipo) {
                case r.diamond:
                    this.icon.spriteFrame = this.diamond,
                this.value = s.Util.getRandomInt(50, 100),
                this.nameReward.string = "钻石";
                break;
                default: this.icon.spriteFrame = this.gold;
                var c = s.Util.itemHighestLevel() >= 10;
                this.value = c ? Math.ceil(20 * Math.pow(s.Util.itemHighestLevel(), 3)) : s.Util.getRandomInt(6e3, 1e4),
                this.nameReward.string = "金币";
            }
            this.bonusData.value = this.value,
            this.valueLabel.addComponent(p.default).init(1, this.value),
            this.getItemData()
        }
        s.Util.videoExposure(u.VideoTab.dim20)
    },
    e.prototype.init = function(t) {
        this._call = t
    },
    e.prototype.onDisable = function() {
        s.Util.hideBanner(),
        s.Util.hide_VerticalCustomAd(!1),
        s.Util.hide_VerticalCustomAd(!0)
    },
    e.prototype.closeGiftPanel = function() {
        var t = this;
        if (!this.cancelPanel.activeInHierarchy) {
            this.giftPanel.active = !1,
            this.cancelPanel.active = !0;
            var e = h.default.nTotalGame % 6;
            s.Util.is_qg() && !h.default.bAuditMode && h.default.nativeMistakeBannerList[e] && s.Util.showNativeGridAd(this.btnShowAd,
            function() {
                t.btnClose.active = !1,
                t.closeNode.active = !0
            }),
            h.default.videoTab = 24,
            s.Util.videoExposure(h.default.videoTab),
            (s.Util.is_qg() || s.Util.is_tt() || s.Util.is_wx()) && s.Util.showBanner(),
            h.default.bAuditMode || !h.default.isShowMistakeBanner || (this.mistakeBannerTimer = setTimeout(function() {
                s.Util.showMistakeBanner(function() {
                    t.mistakeBannerTimer = setTimeout(function() {
                        s.Util.hideMistakeBanner(),
                        s.Util.showBanner()
                    },
                    2e3)
                },
                function() {
                    s.Util.showBanner()
                })
            },
            1e3))
        }
    },
    e.prototype.close = function() {
        clearTimeout(this.mistakeBannerTimer),
        s.Util.hideMistakeBanner(),
        this.node.destroy(),
        s.Util.hideBanner(),
        s.Util.hideNativeBanner(),
        s.Util.hide_VerticalCustomAd(!1),
        s.Util.hide_VerticalCustomAd(!0)
    },
    e.prototype.onClickNativeBanner = function() {
        s.Util.clickNativeBanner(2)
    },
    e.prototype.onClickNativeGridAd = function() {
        s.Util.clickNativeGridAd()
    },
    e.prototype.canel = function() {
        if (this.isBtnClickOnce || h.default.bAuditMode || !h.default.isShowMistakeBanner) {
            this.isBtnClickOnce = !1,
            clearTimeout(this.mistakeBannerTimer),
            s.Util.hide_VerticalCustomAd(!1),
            s.Util.hide_VerticalCustomAd(!0),
            s.Util.hideMistakeBanner(),
            this.node.destroy(),
            s.Util.hideBanner();
            var t = new Date().getTime() + 6e4;
            f.BaseStorage.setInt(u.BaseStorageKey.GiftPackage, t),
            this._canel()
        } else this.isBtnClickOnce = !0
    },
    e.prototype.getItemData = function() {
        var t, e, o;
        switch (s.Util.getRandomInt(0, 5)) {
            case 0:
                e = l.getBodyIdList()[s.Util.getRandomInt(0, l.getBodyIdList().length)],
            o = l.getBodyData(e);
            break;
            case 1:
            case 2:
                e = l.getWheelIdList()[s.Util.getRandomInt(0, l.getWheelIdList().length)],
            o = l.getWheelData(e);
            break;
            case 3:
                e = l.getWeaponIdList()[s.Util.getRandomInt(0, l.getWeaponIdList().length)],
            o = l.getWeaponData(e);
            break;
            case 4:
                e = l.getToolsIdList()[s.Util.getRandomInt(0, l.getToolsIdList().length)],
            o = l.getToolsData(e);
        }
        this.bonusData.data = o,
        cc.sys.localStorage.setItem(u.BaseStorageKey.GiftPackageBonus, JSON.stringify(this.bonusData)),
        this.nameLabel.string = o.name,
        t = {
            data: o,
            star: 3
        },
        this.itemScript.updateView(this.getCarItemData(t.data, t.star)),
        this.allItemsData.push(this.getCarItemData(t.data, t.star))
    },
    e.prototype.getCarItemData = function(t, e) {
        return s.Util.getItemData(t.id, t.type, e, l.GetRandomItemHp(t, e), l.GetRandomItemDamage(t, e), l.GetRandomItemElec(t, e), t.quality)
    },
    e.prototype.onBtnClick = function() {
        var t = this;
        h.default.videoTab = u.VideoTab.dim20,
        s.Util.showRewardVideo(function() {
            s.Util.is_tt() ? setTimeout(function() {
                t.getGiftBonus()
            },
            1e3) : t.getGiftBonus()
        })
    },
    e.prototype.onBtnClickSecondPage = function() {
        var t = this;
        h.default.videoTab = 24,
        s.Util.showRewardVideo(function() {
            s.Util.is_tt() ? setTimeout(function() {
                t.getGiftBonus()
            },
            1e3) : t.getGiftBonus()
        })
    },
    e.prototype.getGiftBonus = function() {
        switch (this._call(), this.tipo) {
            case r.diamond:
                _.default.getIntance().expt_GetDiamond(this.value),
            h.default.saveDiamondData(!0, this.value),
            cc.find("Canvas").getComponent(d.default).onSetOwnDiamond();
            break;
            default: _.default.getIntance().expt_GetGold(this.value),
            h.default.saveGoldData(!0, this.value),
            cc.find("Canvas").getComponent(d.default).onSetOwnGold();
        }
        this.unpack(this.boxPrefab, c.Box_Type.middle),
        h.default.saveOwnCarData(this.allItemsData),
        this.close()
    },
    e.prototype.unpack = function(t, e) {
        var o = cc.instantiate(t);
        cc.find("Canvas").addChild(o, 100),
        o.getComponent(c.default).showOpenBoxView(e, cc.find("Canvas").getComponent(d.default))
    },
    a([C(cc.Prefab)], e.prototype, "pfb_showItem", void 0),
    a([C(cc.Node)], e.prototype, "node_showItem", void 0),
    a([C(cc.Prefab)], e.prototype, "boxPrefab", void 0),
    a([C(cc.Label)], e.prototype, "valueLabel", void 0),
    a([C(cc.Label)], e.prototype, "nameLabel", void 0),
    a([C(cc.Sprite)], e.prototype, "icon", void 0),
    a([C(cc.SpriteFrame)], e.prototype, "gold", void 0),
    a([C(cc.SpriteFrame)], e.prototype, "diamond", void 0),
    a([C(cc.Node)], e.prototype, "giftPanel", void 0),
    a([C(cc.Node)], e.prototype, "cancelPanel", void 0),
    a([C(cc.Label)], e.prototype, "nameReward", void 0),
    a([C(cc.Node)], e.prototype, "closeNode", void 0),
    a([C(cc.Node)], e.prototype, "btnClose", void 0),
    a([C(cc.Node)], e.prototype, "btnShowAd", void 0),
    a([C(cc.Node)], e.prototype, "videoIcon", void 0),
    a([C(cc.Node)], e.prototype, "TTVideoIcon", void 0),
    a([C(cc.Node)], e.prototype, "videoIcon2", void 0),
    a([C(cc.Node)], e.prototype, "TTVideoIcon2", void 0),
    a([C(cc.Node)], e.prototype, "btnCancel", void 0),
    a([C(cc.Node)], e.prototype, "btnGet", void 0),
    a([C(cc.Node)], e.prototype, "btnCancel2", void 0),
    a([C(cc.Node)], e.prototype, "btnGet2", void 0),
    a([v], e)
} (cc.Component);
o.default = b